import Vue from 'vue'
import App from './App.vue'
import moment from 'moment'
import ElButton from './components/ElButton.vue'

Vue.component('ElButton', ElButton)
// import dayjs from 'dayjs'

Vue.config.productionTip = false

// 方法1：
Vue.filter('handleSum', (val, a) => {
  if (a === '万') return `${val / 10000}${a}`
  else return `${val / 1000}${a}`
})

// 方法2：
Vue.filter('handleSum1', (val, a, b) => {
  const item = val.toString()
  const index = item.indexOf(a) + 1
  return `${item.slice(0, index)}.${item.slice(index)}${b}`
})

// 方法3：
Vue.filter('handleSum2', (val, a, b) => {
  const arr = val.toString().split('')
  const index = arr.findIndex(item => item === a)
  arr.splice(index + 1, 0, '.')
  const arrs = arr.join('')
  return arrs + b
})

// 方法1：
Vue.filter('handleDate', (val, a) => {
  const date = new Date(val)
  const y = date.getFullYear()
  const m = (date.getMonth() + 1).toString().padStart(2, 0)
  const d = (date.getDate()).toString().padStart(2, 0)

  return `${y}${a}${m}${a}${d}`
})

// 方法2：
Vue.filter('handleDate1', (val, a) => {
  const date = new Date(val)
  /*  if (a === '/') return dayjs(date).format('YYYY/MM/DD')
  else return dayjs(date).format('YYYY-MM-DD') */
  if (a === '/') return moment(date).format('YYYY/MM/DD')
  else return moment(date).format('YYYY-MM-DD')
})

new Vue({
  render: h => h(App)
}).$mount('#app')
